Expand the tuple contextual type to the target's shape when it comes from a binding pattern#52630
Expand the tuple contextual type to the target's shape when it comes from a binding pattern#52630Andarist wants to merge 2 commits intomicrosoft:mainfrom
Conversation
| // this allows us to infer tuples even if the binding pattern is shorter than the target type, like here: | ||
| // declare function fn<T>(t: T) => [T, string[]]; | ||
| // const [[x]] = fn(['hi']); | ||
| else if (isTupleType(contextualType) && isTupleType(inferenceTargetType)) { |
There was a problem hiding this comment.
this doesn't handle the case when inferenceTargetType is a union of tuple types but I have no idea how "expansion" towards that shape should work - unless all union members would have the very same shape
…from a binding pattern
|
This seems pretty reasonable to me. @typescript-bot user test this |
|
Heya @andrewbranch, I've started to run the diff-based top-repos suite on this PR at cfc350b. You can monitor the build here. Update: The results are in! |
|
Heya @andrewbranch, I've started to run the diff-based user code test suite on this PR at cfc350b. You can monitor the build here. Update: The results are in! |
|
Heya @andrewbranch, I've started to run the perf test suite on this PR at cfc350b. You can monitor the build here. Update: The results are in! |
|
@andrewbranch Here are the results of running the user test suite comparing Everything looks good! |
|
@andrewbranch Here are the results of running the top-repos suite comparing Everything looks good! |
|
@andrewbranch Here they are:
CompilerComparison Report - main..52630
System
Hosts
Scenarios
TSServerComparison Report - main..52630
System
Hosts
Scenarios
StartupComparison Report - main..52630
System
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Conflicts: # tests/baselines/reference/inferTupleFromBindingPattern.js # tests/baselines/reference/inferTupleFromBindingPattern.symbols # tests/baselines/reference/inferTupleFromBindingPattern.types
| resultFlags = source.target.elementFlags.slice(); | ||
| } | ||
| const targetFlag = target.target.elementFlags[i]; | ||
| resultTypes.push(anyType); |
There was a problem hiding this comment.
Rather than any with the target flags, shouldn't it be never with the optional flag? To reflect how the consumer never reads the member?
|
This gets superseded by #56875 since this PR here aimed to solve the problem through special-casing and the new PR takes a much more general approach to this and similar problems. |
fixes #42969
cc @andrewbranch